Skip to content

Fix/spacing investigation#49

Open
bdtran2002 wants to merge 10 commits intomainfrom
fix/spacing-investigation
Open

Fix/spacing investigation#49
bdtran2002 wants to merge 10 commits intomainfrom
fix/spacing-investigation

Conversation

@bdtran2002
Copy link
Copy Markdown
Contributor

This pull request introduces several improvements to the LaTeX cheat sheet generator, focusing on layout flexibility, LaTeX spacing customization, and a more robust API/frontend integration. The main updates include support for up to 4 columns, enhanced LaTeX spacing controls, and improved handling of cases where no formulas are selected. Additionally, the frontend now dynamically regenerates LaTeX headers/footers when layout options change, ensuring the preview always matches user selections.

Layout and Customization Enhancements:

  • Increased the maximum number of columns from 3 to 4 in both backend validation (validate_layout_params in backend/api/views.py) and frontend options (LayoutOptions in frontend/src/components/CreateCheatSheet.jsx). [1] [2]
  • Expanded the LaTeX spacing presets in SPACING_MAP to include a baselineskip value, allowing for more granular control over line spacing in the generated document (backend/api/latex_utils.py).
  • Updated the LaTeX header generation to set \baselineskip according to the selected spacing preset (build_dynamic_header in backend/api/latex_utils.py). [1] [2]

API and Logic Improvements:

  • Changed the /api/generate-sheet/ endpoint to return a valid (empty) LaTeX document with a 200 status code when no formulas are selected, instead of returning a 400 error. Corresponding tests were updated to reflect this behavior (backend/api/views.py, backend/api/tests.py). [1] [2]
  • Modified the LaTeX formula rendering to wrap formulas in $... within the \adjustbox for better compatibility (build_latex_for_formulasinbackend/api/latex_utils.py`).

Frontend Integration:

  • The frontend now requests a regenerated LaTeX header/footer from the backend whenever layout options (columns, font size, spacing, margins) change, and inserts the user's content into the new template for accurate preview (useLatex in frontend/src/hooks/latex.js). [1] [2]
  • Adjusted the layout of the CreateCheatSheet component to better organize layout controls and the editor/preview (frontend/src/components/CreateCheatSheet.jsx). [1] [2]

Other:

  • Added an .opencode/opencode.json configuration file for plugin support.

The spacing setting only controlled section/subsection header spacing, not actual line spacing. This adds baselineskip control so 'tiny' actually reduces line spacing significantly.

- Add baselineskip values to SPACING_MAP (6pt/8pt/11pt/14pt for tiny/small/medium/large)
- Add \setlength{\baselineskip}{X} to dynamic header generation
- Update formula_gap extraction to handle 6-element tuple
- Make tiny spacing truly tiny (baselineskip 4pt vs 6pt)
- Fix recompile to apply current layout options (columns, fontSize, spacing, margins)
- Add 4-column option to dropdown and backend validation
- Add proper React dependencies to handleCompileOnly
…ns to bottom

- Backend: generate-sheet now returns valid LaTeX even with empty formulas (for recompile)
- Frontend: recompile (middle circle button) now regenerates with current layout options
- Add 4-column option to dropdown
- Move LayoutOptions from top selection panel to bottom editor panel
- Update tests for new empty formulas behavior
Previously recompile replaced entire content with empty formula template, causing empty document error.
Now it extracts the body from existing content and merges with new layout header.
- LayoutOptions now appears at top of editor/preview panel (above LaTeX editor)
- Simplify merge logic to extract and preserve document body
- Fix missing \end{document} in merged output
The old merge logic kept the old multicols wrapper which overrode
the new column count. Now it extracts just the formula content
from the old body and inserts it into the new layout's multicols
environment, preserving the new column/spacing settings.
Copilot AI review requested due to automatic review settings April 9, 2026 21:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the LaTeX cheat sheet generator’s layout flexibility and frontend/backend integration, adding support for 4 columns, new spacing controls, and improved handling of “no formulas selected” requests.

Changes:

  • Extend layout options (backend validation + frontend UI) to support up to 4 columns.
  • Add/propagate new LaTeX spacing behavior (including \baselineskip) and tweak formula rendering.
  • Update API + frontend to handle empty selections more gracefully and to regenerate LaTeX templates when layout options change.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
frontend/src/hooks/latex.js Regenerates LaTeX template on layout changes before compiling to keep preview aligned.
frontend/src/components/CreateCheatSheet.jsx Adds 4-column option and reorganizes layout controls vs editor/preview panels.
backend/api/views.py Allows up to 4 columns; returns empty-but-valid LaTeX when no formulas are selected.
backend/api/tests.py Updates generate-sheet endpoint tests to expect 200 + tex_code for empty/missing formulas.
backend/api/latex_utils.py Adds baselineskip to spacing presets and updates LaTeX generation (header + formula rendering).
.opencode/opencode.json Adds OpenCode plugin configuration file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 71 to 76
f"\\titlespacing*{{\\section}}{{0pt}}{{{sec_before}}}{{{sec_after}}}",
f"\\titlespacing*{{\\subsection}}{{0pt}}{{{subsec_before}}}{{{subsec_after}}}",
f"\\setlength{{\\baselineskip}}{{{baseline_skip}}}",
"",
"\\begin{document}",
size_command,
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\setlength{\baselineskip}{...} is set before \begin{document} and before applying the selected font size command. In LaTeX, changing font size (e.g. \footnotesize/\tiny) typically resets \baselineskip, so this line may have no effect. Consider applying the baselineskip after the size command (or using \AtBeginDocument / \fontsize{...}{...}\selectfont) so the spacing preset actually takes effect.

Copilot uses AI. Check for mistakes.
Comment on lines 153 to 155
body_lines.append("\\textbf{" + escaped_name + "}")
body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{\\displaystyle " + latex + "} \\]")
body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{$" + latex + "$} \\]")
body_lines.append(f"\\\\[{formula_gap}]")
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wraps the formula in $...$ while already inside a display-math environment ([ ... ]). Nested math shifts will cause LaTeX compilation errors. Either keep [ ... ] and pass math-mode content to adjustbox (e.g. without $...$), or remove [ ... ] and rely on $...$ inside adjustbox in text mode.

Copilot uses AI. Check for mistakes.
Comment on lines +158 to +162
const multicolMatch = oldBody.match(/\\begin\{multicols\}\{(\d+)\}([\s\S]*?)\\end\{multicols\}/);

let formulaContent = oldBody;
if (multicolMatch) {
formulaContent = multicolMatch[2];
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multicolumn body extraction captures everything after the column count, which includes template scaffolding like \raggedcolumns. When you later prepend the regenerated template's own content, this can duplicate \raggedcolumns (and any other boilerplate inside the multicols block), making the merged LaTeX inconsistent. Consider extracting only the user-authored portion (e.g., strip leading \raggedcolumns/blank lines) before reinserting.

Copilot uses AI. Check for mistakes.
Comment on lines +173 to +177

contentToCompile = newParts[0] + '\\begin{multicols}' + columnCount + '}' + beforeEnd + formulaContent + '\\end{multicols}' + afterEnd;
} else {
contentToCompile = newLatex;
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the regenerated template does not contain a multicols environment (e.g. columns === 1), this branch sets contentToCompile = newLatex, which discards the existing document body/formulas entirely and results in compiling an empty sheet. The merge logic should handle the no-multicols case by preserving the old document body and injecting it into the regenerated header/footer (or wrapping/unwrapping multicols appropriately when toggling between 1 and >1 columns).

Copilot uses AI. Check for mistakes.
Comment on lines +73 to 76
f"\\setlength{{\\baselineskip}}{{{baseline_skip}}}",
"",
"\\begin{document}",
size_command,
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new baselineskip behavior isn’t covered by existing API tests (e.g., test_generate_sheet_with_spacing only asserts that titlespacing exists). Consider adding an assertion that the generated LaTeX includes the expected \setlength{\baselineskip}{...} for a given spacing preset, so regressions in spacing presets are caught.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants